﻿CREATE TABLE [dbo].[Video]
(
	[VideoID]     		uniqueidentifier NOT NULL,
	[VideoFileID]		uniqueidentifier NOT NULL,
	[SongID]			uniqueidentifier NOT NULL,
    [EventID]			uniqueidentifier NULL,
    [VersionID]			uniqueidentifier NULL,
    [DateLastPlayed]   	datetime NULL,
    [DateProduced]     	date NULL,
    [PlayCount]			smallint NOT NULL DEFAULT ((0)),
    [SkipCount]			smallint NOT NULL DEFAULT ((0)),
    [CalculatedRating] 	tinyint NULL,
    [UserRating]       	tinyint NULL,
	[StartPosition]		time NULL,
    [Length]			time NULL,
    [ThumbnailPosition]	time NULL,
    [ThumbnailFilePath]	varchar(900) NULL,
    [SyncToPMP]			bit NOT NULL DEFAULT ((0)),
    CONSTRAINT [PK_Video] PRIMARY KEY([VideoID]),
    CONSTRAINT [UQ_Video_Song]	UNIQUE ([VideoFileID],[SongID],[EventID],[VersionID]),
    CONSTRAINT [FK_Video_VideoFileID] FOREIGN KEY([VideoFileID]) REFERENCES [dbo].[VideoFile]([VideoFileID]),
    CONSTRAINT [FK_Video_SongID] FOREIGN KEY([SongID]) REFERENCES [dbo].[Song]([SongID]),
	CONSTRAINT [FK_Video_EventID] FOREIGN KEY([EventID]) REFERENCES [dbo].[Event]([EventID]),
	CONSTRAINT [FK_Video_VersionID] FOREIGN KEY([VersionID]) REFERENCES [dbo].[Version]([VersionID])
)